<template>
	<gui-page>
		<template v-slot:gBody>
			<view class="gui-bg-white gui-dark-bg-level-3 gui-padding">
				<cardBody :icon="'&#xe692;'" :title="'设备名'" :value="`${item.devname}`"></cardBody>
				<cardBody :icon="'&#xe692;'" :title="'名称'" :value="`${item.mc}`"></cardBody>
				<cardBody :icon="'&#xe692;'" :title="'设备类型'" :value="`${item.devtype}`"></cardBody>
				<cardBody :icon="'&#xe692;'" :title="'设备编号'" :value="`${item.bh}`"></cardBody>
				<cardBody :icon="'&#xe692;'" :title="'电流互感器变比'" :value="`${item.ctbb}`"></cardBody>
				<cardBody :icon="'&#xe692;'" :title="'设备序列号'" :value="`${item.xlh}`"></cardBody>
				<cardBody :icon="'&#xe692;'" :title="'设备描述'" :value="`${item.info}`"></cardBody>
				<cardBody :icon="'&#xe692;'" :title="'GPS经纬度'" :value="`(${item.gps_jd},${item.gps_wd})`"></cardBody>
				<cardBody :icon="'&#xe692;'" :title="'安装地址'" :value="`${item.addr}`"></cardBody>	
				<view class="gui-list-items" >
					<text class="gui-list-icon gui-icons gui-color-green">&#xe692;</text>
					<view class="gui-list-body gui-border-b">
						<view class="gui-list-title">
							<text class="gui-list-title-text gui-primary-text">在线状态</text>
							<text v-if="item.online == 1" class="gui-list-title-desc gui-color-green">在线</text>
							<text v-if="item.online == 0" class="gui-list-title-desc gui-color-gray">离线</text>
							<text class="gui-list-title-desc gui-color-gray">[{{item.onlinetime}}]</text>
						</view>
					</view>
				</view>
				<cardBody :icon="'&#xe692;'" :title="'最近接收数据时间'" :value="`${item.lastrecvtime}`"></cardBody>
				<cardBody :icon="'&#xe692;'" :title="'设备密钥'" :value="`${item.skey}`"></cardBody>
				<cardBody :icon="'&#xe692;'" :title="'auth授权字符串'" :value="`${item.sauth}`"></cardBody>
				<view class="gui-list-items" v-if="item.isvideo==1"  @click="govideo(item)" >
					<text class="gui-list-icon gui-icons gui-color-red">&#xe63d;</text>
					<view class="gui-list-body gui-border-b">
						<view class="gui-list-title">
							<text class="gui-list-title-text gui-color-red">视频链接</text>
							<text class="gui-list-title-desc gui-color-gray">{{item.videourl}}</text>
						</view>
					</view>
				</view>
				<cardBody :icon="'&#xe692;'" :title="'SPK授权字符串'" :value="`${item.spsk}`"></cardBody>
				<cardBody :icon="'&#xe692;'" :title="'基准线时间日期'" :value="`${item.jzsj}`"></cardBody>
				<cardBody :icon="'&#xe692;'" :title="'基准线日有功电量KWH'" :value="`${item.jz_dayygdl}`"></cardBody>
				<cardBody :icon="'&#xe692;'" :title="'基准线日无功电量Kvar'" :value="`${item.jz_daywgdl}`"></cardBody>
				<view class="gui-list-items" >
					<text class="gui-list-icon gui-icons gui-color-green">&#xe692;</text>
					<view class="gui-list-body gui-border-b">
						<view class="gui-list-title">
							<text class="gui-list-title-text gui-primary-text">是否启用基准线计算</text>
							<text v-if="item.jz_enable == 1" class="gui-list-title-desc gui-color-green">是</text>
							<text v-if="item.jz_enable == 0" class="gui-list-title-desc gui-color-gray">否</text>
						</view>
					</view>
				</view>
				<cardBody :icon="'&#xe692;'" :title="'基准线日平均总电流A'" :value="`${item.jz_dayzdl}`"></cardBody>
				<cardBody :icon="'&#xe692;'" :title="'激活时间'" :value="`${item.jhtime}`"></cardBody>
				<cardBody :icon="'&#xe692;'" :title="'创建时间'" :value="`${item.create_time}`"></cardBody>
				<cardBody :icon="'&#xe692;'" :title="'更新时间'" :value="`${item.update_time}`"></cardBody>
			</view>
		</template>
	</gui-page>
</template>

<script setup>
	import { ref,getCurrentInstance,createApp } from 'vue'
	import { onLoad,onPullDownRefresh } from '@dcloudio/uni-app'
	import cardBody from "@/lib/components/card-body.vue"
	import guiPage from "@/Grace6/components/gui-page.vue"
	import ybmethod from '../../lib/js/ybmethod';
	import ybgolbal from '../../lib/js/ybgolbal';
	const ybapi = ybgolbal.getybapi(getCurrentInstance());   // 定义与后端接口进行交互的变量
	const app = createApp(); 
	let devid = ref(0);    // 设备id
	let item = ref({});    // 存放设备详情数据的对象
	
	onLoad((option)=>{
		console.log("进入设备详情页面");
		devid.value = option.devid;
		console.log(option);
		getData();
	})
	
	// 上拉刷新
	onPullDownRefresh(()=>{
		ybmethod.onPullDownRefresh(getData);
	})
	
	// 获取设备详情数据
	function getData(){
		ybapi.Devices_GetDeviceInfo(devid.value,function(data){
			console.log(data)
			item.value = data;
		})
	}
	
	// 视频链接打开函数
	function govideo(item){
		console.log(item.videourl);
		// #ifdef H5
			window.location.href = item.videourl;
		// #endif
		// #ifdef APP-PLUS
			plus.runtime.openURL(item.videourl);
		// #endif
	}
	
	// 局部注册组件
	app.component({
		cardBody,
		guiPage
	})
</script>

<style>
	       
</style>
